{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "639546bb-e05d-4b51-b0ea-3f9bb965d780",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import django\n",
    "\n",
    "os.environ['DJANGO_SETTINGS_MODULE'] = 'modelProject.settings'\n",
    "os.environ[\"DJANGO_ALLOW_ASYNC_UNSAFE\"] = \"true\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c097ec70-b506-498a-830d-7cb5580236f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/data/hrwang/gpt_all/venv/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "No sentence-transformers model found with name /data/hrwang/gpt_all/gptcache_database_manage_milvus/embedding_models/text2vec_large. Creating a new one with MEAN pooling.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1024,)\n",
      "connection success\n"
     ]
    }
   ],
   "source": [
    "django.setup()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4adf242b-8606-4750-91f2-8d5c642627e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from knowledge1.models import Base, Detail, Project"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e59ac668-f031-4b49-a582-4da3e73b97c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 20 ms, sys: 9.95 ms, total: 30 ms\n",
      "Wall time: 34.6 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'status': 200, 'message': '向量数据恢复成功！'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "# 历史对话\n",
    "import requests\n",
    "url = \"http://180.184.214.46:31690/history_qa/recover_data/\"\n",
    "res = requests.post(url)\n",
    "res.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "492c1880-4898-4b6a-96b0-2e83a84c3bc5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 7.08 ms, sys: 7.35 ms, total: 14.4 ms\n",
      "Wall time: 17.2 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "# 知识\n",
    "project_list = [obj.name for obj in Project.objects.all()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f4d6ec32-411d-4942-b4f2-32440d1bc4be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['legal_articles_qa',\n",
       " 'custom_qa',\n",
       " 'park_qa',\n",
       " 'insurance_qa',\n",
       " 'unidt_qa',\n",
       " 'test',\n",
       " 'patent',\n",
       " 'governance',\n",
       " 'enterprise_qa',\n",
       " 'test_project',\n",
       " 'ZKTEST_8384_1',\n",
       " 'TEST_ZK_2800_2',\n",
       " 'shehuizhilitest_7895_2',\n",
       " 'zhadayinhang_8112_1',\n",
       " 'zhadayinhang_5712_2',\n",
       " 'huifeng_1168',\n",
       " 'huifeng_2864',\n",
       " 'zhadayinhang',\n",
       " 'code_repo',\n",
       " 'zhongguoyinhang',\n",
       " 'test00',\n",
       " 'dianshang',\n",
       " 'yiliao',\n",
       " 'wenlv',\n",
       " '111',\n",
       " '1',\n",
       " 'customs',\n",
       " 'huayuan',\n",
       " 'yonghukongjian',\n",
       " 'huayuanzhishi',\n",
       " 'code']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "project_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "51dadd9f-909b-4e6f-8ddc-c4aa0340c73f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': '已恢复向量数据库', 'time': '2753.6306431293488'}\n",
      "{'result': '已恢复向量数据库', 'time': '33.41122031211853'}\n",
      "{'result': '已恢复向量数据库', 'time': '64.9709267616272'}\n",
      "{'result': '已恢复向量数据库', 'time': '129.9504804611206'}\n",
      "{'result': '已恢复向量数据库', 'time': '74.1764805316925'}\n",
      "{'result': '已恢复向量数据库', 'time': '9.819926023483276'}\n",
      "{'result': '已恢复向量数据库', 'time': '142.52392840385437'}\n",
      "{'result': '已恢复向量数据库', 'time': '13.682852983474731'}\n",
      "{'result': '已恢复向量数据库', 'time': '10.415867805480957'}\n",
      "{'result': '已恢复向量数据库', 'time': '17.780277729034424'}\n",
      "{'result': '已恢复向量数据库', 'time': '10.518510341644287'}\n",
      "{'result': '已恢复向量数据库', 'time': '10.23073935508728'}\n",
      "{'error': '该shehuizhilitest_7895_2项目下无数据', 'time': '0.07598090171813965'}\n",
      "{'error': '该zhadayinhang_8112_1项目下无数据', 'time': '0.07791733741760254'}\n",
      "{'error': '该zhadayinhang_5712_2项目下无数据', 'time': '0.07685995101928711'}\n",
      "{'error': '该huifeng_1168项目下无数据', 'time': '0.07950329780578613'}\n",
      "{'error': '该huifeng_2864项目下无数据', 'time': '0.0758514404296875'}\n",
      "{'error': '该zhadayinhang项目下无数据', 'time': '0.06937265396118164'}\n",
      "{'result': '已恢复向量数据库', 'time': '10.286388635635376'}\n",
      "{'error': '该zhongguoyinhang项目下无数据', 'time': '0.0817868709564209'}\n",
      "{'error': '该test00项目下无数据', 'time': '0.06989192962646484'}\n",
      "{'error': '该dianshang项目下无数据', 'time': '0.07072925567626953'}\n",
      "{'result': '已恢复向量数据库', 'time': '43.78476619720459'}\n",
      "{'result': '已恢复向量数据库', 'time': '14.948878049850464'}\n",
      "{'error': '该111项目下无数据', 'time': '0.09108567237854004'}\n",
      "{'error': '该1项目下无数据', 'time': '0.07310605049133301'}\n",
      "{'result': '已恢复向量数据库', 'time': '28.762500047683716'}\n",
      "{'error': '该huayuan项目下无数据', 'time': '0.0820918083190918'}\n",
      "{'error': '该yonghukongjian项目下无数据', 'time': '0.06949973106384277'}\n",
      "{'error': '该huayuanzhishi项目下无数据', 'time': '0.07997488975524902'}\n",
      "{'result': '已恢复向量数据库', 'time': '8.156978607177734'}\n",
      "CPU times: user 1.1 s, sys: 1.2 s, total: 2.29 s\n",
      "Wall time: 56min 20s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "import requests\n",
    "url = 'http://113.31.111.86:19108/knowledge1/recover_data/'\n",
    "# project_list = [\"wenlv\"]\n",
    "for project in project_list:\n",
    "    data = {\n",
    "            \"project\": project,\n",
    "            }\n",
    "    res = requests.post(url=url, data=data)\n",
    "    print(res.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e1c30c6-c4d7-4d4b-a8d9-0d81e92b21b7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "django",
   "language": "python",
   "name": "venv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
